#ifndef AED_PHYSICSCOMP_H
#define AED_PHYSICSCOMP_H

#include <QString>
#include <QList>
#include <QTextStream>
#include <QDomDocument>

using namespace std;

class AED_PhysicsComp
{
public:
    struct Condition{
        QString name;
        QString attr;
        int omega;
        bool inv;

        Condition(const QString &n, QString a, int o, bool i):name(n),attr(a),omega(o),inv(i){}
        Condition(const Condition &cond){name = cond.name; attr = cond.attr; omega = cond.omega; inv = cond.inv;}
        bool operator==(const Condition &cond){if(name==cond.name && attr == cond.attr && omega == cond.omega && inv == cond.inv) return true; return false;}
    };

    struct Point{
        float x, y;
        Point(){x=0;y=0;}
        Point(float x_, float y_){x=x_;y=y_;}
        Point(const Point &pt){x=pt.x; y=pt.y;}
        bool operator==(const Point &pt){if(x==pt.x && y==pt.y) return true; return false;}
    };

private:
    QList<Condition> m_conds;
    bool m_enabled;

    float m_friction;
    float m_restitution;
    bool m_sensor;
    QString m_shape; 	//circle/box/polygon
    float m_shape_size_x;
    float m_shape_size_y;
    float m_linear_damping;
    float m_angular_damping;
    QString m_type; 	//static/dynamic
    bool m_fixed_rotation;
    bool m_bullet;
    float m_density;
    QList<Point> m_points; 	//float float

public:
    AED_PhysicsComp();
    AED_PhysicsComp& operator =(const AED_PhysicsComp &comp);

    void AddCondition(const QString &name, const QString &attr, int omega, bool inv);
    void RemoveCondition(int index);
    QList<Condition>* GetConditionList();

    bool IsEnabled();
    void SetEnabled(bool enabled);

    float GetFriction(){return m_friction;}
    void SetFriction(float fric){m_friction=fric;}
    float GetRestitution(){return m_restitution;}
    void SetRestitution(float rest){m_restitution=rest;}
    bool GetSensor(){return m_sensor;}
    void SetSensor(bool sensor){m_sensor=sensor;}
    QString GetShape(){return m_shape;}
    void SetShape(const QString &shape){m_shape = shape;}
    float GetShapeSizeX(){return m_shape_size_x;}
    void SetShapeSizeX(float size){m_shape_size_x=size;}
    float GetShapeSizeY(){return m_shape_size_y;}
    void SetShapeSizeY(float size){m_shape_size_y=size;}
    float GetLinearDamping(){return m_linear_damping;}
    void SetLinearDamping(float damp){m_linear_damping=damp;}
    float GetAngularDamping(){return m_angular_damping;}
    void SetAngularDamping(float damp){m_angular_damping=damp;}
    QString GetType(){return m_type;}
    void SetType(const QString &type){m_type = type;}
    bool GetFixedRotation(){return m_fixed_rotation;}
    void SetFixedRotation(bool rot){m_fixed_rotation = rot;}
    bool GetBullet(){return m_bullet;}
    void SetBullet(bool bullet){m_bullet=bullet;}
    float GetDensity(){return m_density;}
    void SetDensity(float density){m_density=density;}
    QList<Point>* GetPoints(){return &m_points;}
    void AddPoint(float x, float y){m_points.append(Point(x,y));}
    void RemovePoint(int index){m_points.removeOne(m_points[index]);}

    void Save(QTextStream &file);
    void Save(QDomDocument &doc, QDomElement &pelem);

    void Load(QDomElement &celem);

};

#endif // AED_PHYSICSCOMP_H
